from flask import Flask, request
import sqlite3
from MAIN.db1 import *
app = Flask(__name__)


@app.route('/')
def hello_world():  # put application's code here
    return 'Hello World!'


def SuperControl(cmd,choice=0):
    Dict = {}
    result = ""
    if request.method == "POST":
        if request.content_type.startswith('application/json'):
            # comment = request.get_json()["content"]
            comment = request.json.get('content')
        elif request.content_type.startswith('multipart/form-data'):
            Dict = request.form

            result = superControl(cmd,Dict,choice)
        else:
            comment = request.values.get("content")
    # logger.debug('%s' % comment)
            print(comment)
            print(type(comment))
    #
    if choice >=4:
        return result
    else:
        return Dict


@app.route('/Box_contain/<int:choice>', methods=["POST"])
def Box_contain(choice):
    result = SuperControl("Box_Contain",choice)
    print("super", result)
    return result


@app.route('/Device/<int:choice>', methods=["POST"])
def Device(choice):
    result = SuperControl("Device",choice)
    print(result)
    return result


@app.route('/Sign_up/<int:choice>', methods=["POST"])
def Sign_up(choice):
    result = SuperControl("Sign_up",choice)
    print(result)
    return result


@app.route('/history/<int:choice>', methods=["POST"])
def history(choice):
    result = SuperControl("history",choice)
    print(result)
    return result


if __name__ == '__main__':
    app.run()
